<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    </head>
</head>
<body>
<br><br><br>


<input type="hidden" id="commodityTypeId" value="${commodityTypeId}">

<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>

<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table">
            <colgroup>
                <col width="200">
                <col width="200">
                <col width="300">

                <col>
            </colgroup>
            <thead>
            <tr>

                <th>卡名称</th>
                <th>卡代码</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="men" >
                <tr>

                    <td>
                            ${men.name}
                    </td>
                    <td>
                            ${men.code}
                    </td>
                    <td>
                        <div class="layui-input-block">

                            <input type="checkbox" name="close" <c:if test="${sxkCommodityId eq men.id}">checked</c:if>
                                   value="${men.id}" lay-filter="switchK" lay-skin="switch" lay-text="已关联|未关联" />


                        </div>

                    </td>

                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>

    <div id="fenye"></div>

    <div id="under" style="margin-top: 20rem"></div>

</div>

<script>
    layui.use('laypage', function(){
        var laypage = layui.laypage;
        laypage.render({
            elem: 'fenye'
            ,count: ${pageUtil.totalRows}
            ,limit:10//数据总数，从服务端得到
            ,curr:${pageUtil.currentPage}
            ,hash:true
            ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据
                console.log(obj.limit); //得到每页显示的条数
                var commodityTypeId=$("#commodityTypeId").val();
                //首次不执行
                if(!first){
                    window.location.href="/shop/showSuXiaoKa?faceValueId=${facevalueId}&page="+obj.curr+"&limit="+obj.limit;
                }
            }
        });
    });
    $(function () {
        var cc=$("#commodityTypeId").val();
        $("#katype").val(cc);
        var array = new Array();  //定义数组
            $("#katype option").each(function () {
                var val = $(this).val();
                array.push(val);
            })
    })
    function aa() {
        var  cc= $("#katype option:selected").val();
        window.location.href="/shop/showXianka?type="+cc;
    }
</script>

<script>

    layui.use(['form', 'table'], function () {
        var table = layui.table;
        var form = layui.form;


        //监听指定开关
        form.on('switch(switchK)', function(data){
            var flag=this.checked;
            // var newXkId=data.value;

            $.ajax({
                url:'/shop/saveSXKFaceValueId',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{'id':data.value,'hasNumber':this.checked,'facevalueId':'${facevalueId}'},
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(reData){
                    if(!reData.result){
                        layui.use('layer',function(){
                            layer.msg('修改失败');
                        });
                    }else{
                        layui.use('layer',function(){
                            layer.msg('更改成功');
                        });
                        window.location.reload();

                    }

                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });


        });
    });

</script>

</body>
</html>